﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQ.Security.Criptografia
{
    public static class Criptografia
    {

        private static Dictionary<int, String> dicionarioCriptografia = CriarDicionarioCriptografia();
        private static Dictionary<String, String> dicionarioDecriptografia = CriarDicionarioDecriptografia();

        public static String Criptografar(String senha)
        {
            String resposta = "";

            foreach (var item in senha)
            {
                resposta = resposta + dicionarioCriptografia[int.Parse(item.ToString())];
            }

            return resposta;
        }

        public static String Decriptografar(String senha)
        {
            String resposta = "";

            foreach (var item in senha)
            {
                resposta = resposta + dicionarioDecriptografia[item.ToString()];
            }

            return resposta;
        }

        private static Dictionary<int, String> CriarDicionarioCriptografia()
        {
            Dictionary<int, String> hash = new Dictionary<int, String>();

            hash.Add(0, "K");
            hash.Add(1, "H");
            hash.Add(2, "F");
            hash.Add(3, "D");
            hash.Add(4, "A");
            hash.Add(5, "M");
            hash.Add(6, "Z");
            hash.Add(7, "P");
            hash.Add(8, "Q");
            hash.Add(9, "W");

            return hash;
        }

        private static Dictionary<String, String> CriarDicionarioDecriptografia()
        {
            Dictionary<String, String> hash = new Dictionary<String, String>();

            hash.Add("K", "0");
            hash.Add("H", "1");
            hash.Add("F", "2");
            hash.Add("D", "3");
            hash.Add("A", "4");
            hash.Add("M", "5");
            hash.Add("Z", "6");
            hash.Add("P", "7");
            hash.Add("Q", "8");
            hash.Add("W", "9");

            return hash;
        }
    }
}

